<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>比赛信息管理</title>
    <link rel="stylesheet" href="../res/layui/css/layui.css" media="all">
    <script type="text/javascript" src="../res/js/jquery-3.1.1.min.js"></script>
    <script type="text/javascript" src="../res/layui/layui.js"></script>
    <script type="text/javascript" src="../res/js/Tools.js"></script>
    <script type="text/javascript">
        $.ajaxSetup({
            async:false
        });
    </script>
</head>
<body>
<div id="Beboos">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>比赛信息管理</legend>
    </fieldset>
    <form id="form" class="layui-form">
        <!-- 运动员ID -->
        <div style="display: none">
            <label class="layui-form-label">运动员ID</label>
            <div>
                <input type="text" name="athleteId" id="athleteId"  placeholder="用户ID" class="layui-input">
            </div>
        </div>
        <!-- 本表ID -->
        <div  style="display: none">
            <label class="layui-form-label">本表ID</label>
            <div>
                <input type="text" name="resultId" id="resultId"  placeholder="教练ID" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <!-- 运动员姓名 -->
            <div class="layui-inline">
                <label class="layui-form-label">运动员姓名</label>
                <div class="layui-input-block">
                    <select lay-verify="required" id="athleteName" name="athleteName"  lay-search>
                        <option value="">请选择</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <!-- 比赛名称 -->
            <div  class="layui-inline" >
                <label class="layui-form-label">比赛名称</label>
                <div class="layui-input-block whstandard">
                    <input type="text" name="matchName" id="matchName" lay-verify="required"  placeholder="比赛名称" class="layui-input">
                </div>
            </div>
            <!-- 登陆账号 -->
            <div  class="layui-inline">
                <label class="layui-form-label">比赛时间</label>
                <div class="layui-input-block whstandard">
                    <input type="text" name="matchTime"   id="matchTime"  placeholder="比赛时间" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <!-- 比赛地点 -->
            <div  class="layui-inline">
                <label class="layui-form-label">比赛地点</label>
                <div class="layui-input-block whstandard">
                    <input type="text" name="matchAddr" id="matchAddr" lay-verify="required"  placeholder="比赛地点" class="layui-input">
                </div>
            </div>
            <!-- 比赛项目 -->
            <div  class="layui-inline">
                <label class="layui-form-label">比赛项目</label>
                <div class="layui-input-block whstandard">
                    <input type="text" name="matchItem" id="matchItem"  placeholder="比赛项目" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <!--比赛成绩 -->
            <div  class="layui-inline">
                <label class="layui-form-label">比赛成绩</label>
                <div class="layui-input-block whstandard">
                    <input type="text" name="matchResult" id="matchResult" lay-verify="required" placeholder="比赛成绩" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <!-- 比赛排名 -->
            <div  class="layui-inline">
                <label class="layui-form-label">比赛排名</label>
                <div class="layui-input-block whstandard">
                    <input type="text" name="matchSort" id="matchSort"  placeholder="比赛排名" class="layui-input">
                </div>
            </div>
            <!-- 积分 -->
            <div class="layui-inline">
                <label class="layui-form-label">积分</label>
                <div class="layui-input-block whstandard">
                    <input type="text" name="score" id="score"  placeholder="积分" class="layui-input">
                </div>
            </div>
        </div>
        <!-- 备注 -->
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">其他说明</label>
            <div class="layui-input-block">
                <textarea name="remark" id="remark" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>
        <!-- 提交 -->
        <div class="layui-input-block">
            <button class="layui-btn"id="btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>

    </form>
</div>
</body>
<script type="text/javascript">
    //时间选择器
    layui.use('laydate', function() {
        var laydate = layui.laydate;
        //运动员生日
        laydate.render({
            elem: '#matchTime' //指定元素
            , trigger: 'click'
            //, isInitValue: true //是否填充初始值 是

        });
    });
    var form = null;
    layui.use('form', function(){
        form = layui.form;
        form.render();//渲染
        //监听提交按钮
        form.on('submit(formDemo)', function(data){
            //layer.msg(JSON.stringify(data.field)); //弹出当前表单数据*!/
            var formData = new FormData(document.getElementById("form"));
            var url = "../AtsEmpAthleteResults/insertOrupDate";
            $.ajax({
                type:"post",
                url:url,
                data:formData,
                processData:false,
                contentType:false,
                dataType:"json",
                success:function(obj){
                    var msg = null;
                    if(obj.num ==1){
                        msg ="操作成功"
                    }else{
                        msg = "操作异常"
                    }
                    layer.msg(msg,{icon:1,time:1000},function(){
                        //关闭当前层
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index);
                    });
                }
            })
            return false;
        });
        loadingAthleteName()//加载运动员
        findByid()//根据ID
    });
    function loadingAthleteName(){
        $.ajax({
            type:"post",
            url:"../AtsEmpAthleteResults/loadingAthleteName",
            processData:false,
            contentType:false,
            dataType:"json",
            success:function(obj){
                $.each(obj,function(index,item) {
                    // $("#expertSpecia").append("<option value='"+item.sportId+"'>"+ item.sportName+"</option>")
                    $('#athleteName').append(new Option(item.athleteName, item.athleteId));// 下拉菜单里添加元素

                });
                layui.form.render("select");//渲染下拉框
            }
        })
    }
    function findByid(){
        var id = getQueryString("id");
        //alert(id);
        $.ajax({
            type:"post",
            url:"../AtsEmpAthleteResults/findByid",
            data: {
                id: id
            },
            dataType:"json",
            success:function(obj){
                $("#athleteId").val(obj.athleteId);
                $("#resultId").val(obj.resultId);
                $("#athleteName").val(obj.athleteId);
                $("#matchName").val(obj.matchName);
                $("#matchTime").val(obj.matchTime);
                $("#matchAddr").val(obj.matchAddr);
                $("#matchItem").val(obj.matchItem);
                $("#matchResult").val(obj.matchResult);
                $("#matchSort").val(obj.matchSort);
                $("#score").val(obj.score);
                $("#remark").val(obj.remark);
                form.render();//渲染
            }
        });
    }
</script>
</html>